package com.itheima.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.dao.CampaignSettingDao;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.pojo.CampaignSetting;
import com.itheima.service.CampaignSettingService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author ZhaoShengChao
 * @create 2021/8/7 21:45
 */
@Service(interfaceClass=CampaignSettingService.class)
@Transactional
public class CampaignSettingServiceImpl implements CampaignSettingService {


    @Autowired
    private CampaignSettingDao campaignSettingDao;

    /**
     * 文件上传
     * @param campaignSettings
     */
    @Override
    public void add(List<CampaignSetting> campaignSettings) {
        if (campaignSettings != null&&campaignSettings.size() > 0) {

            for (CampaignSetting campaignSetting : campaignSettings) {
                campaignSettingDao.add(campaignSetting);
            }
        }
    }

    @Override
    public void add(CampaignSetting campaignSetting) {
            campaignSettingDao.add(campaignSetting);
    }

    @Override
    public PageResult pageQuery(QueryPageBean queryPageBean) {
        //当前页
        Integer currentPage = queryPageBean.getCurrentPage();
        //每页显示几条数据
        Integer pageSize = queryPageBean.getPageSize();
        //查询条件
        String queryString = queryPageBean.getQueryString();

        //分页助手插件
        PageHelper.startPage(currentPage,pageSize);

        Page<CampaignSetting> list = campaignSettingDao.findByCondition(queryString);

        //总条数
        long total = list.getTotal();
        //全部数据
        List<CampaignSetting> result = list.getResult();

        return new PageResult(total,result);
    }

    /**
     * 删除数据
     * @param id
     */
    @Override
    public void deleteById(Integer id) {
        campaignSettingDao.deleteById(id);
    }

    /**
     * 编辑运动数据
     * @param campaignSetting
     */
    @Override
    public void edit(CampaignSetting campaignSetting) {
        campaignSettingDao.edit(campaignSetting);
    }
}
